<?php

/*
*	$version: 2009-6-4 am 11:55:10 beta 1.0
*	$id: SessionMemcache.class.php
*	$author: taoFeng
*	$mailto: font99@Gmail.com
*	$license: This is not a freeware
*/

if (!defined('IN_LEKO')) {header("HTTP/1.0 403 Forbidden");exit;}

class SessionMemcache
{
    private $_sessLink;
	private $_storageObj;
	private $_lifeTime = 1440;

	public function open() {
		$this->_lifeTime = ini_get('session.gc_maxlifetime');

		if ($GLOBALS['_G']['sessNewlink']) {
			$_tmp = new newMemcache();
			$this->_storageObj = $_tmp;
			return $_tmp->memcacheSupported;
		}
		else {
			if (is_object($GLOBALS['_C'])) {
				$this->_storageObj = $GLOBALS['_C'];
				return true;
			}
		}

		return false;
	}

	public function read($_sessId) {
		$v = $this->_storageObj->_getCache("sess/{$_sessId}");
		if (!empty($v[0]))
			return $v[0];
	}

	public function write($_sessId,$_sessData) {
		if (!empty($_sessData))
		{
			return $this->_storageObj->_setCache("sess/{$_sessId}",$_sessData,$this->_lifeTime);
		}
	}

	public function destroy($_sessId) {
		return $this->_storageObj->_delCache("sess/{$_sessId}");
	}

	public static function gc() {return true;}
	public static function close() {return true;}

	public function __destruct() {
		session_write_close();
	}
}

?>